<?php
	include_once("ClsSebent/config.php");	
	
	if($_REQUEST['site_id'])
	{
		$_SESSION['SITE_ID']=$_REQUEST['site_id'];	

	}
	
	if(!$_SESSION['SITE_ID'])
	{	
		?>
			<script> location.replace("index.php"); </script>
		<?php
	}
	
	$sql="SELECT * FROM `site_home` WHERE `id`='".$_REQUEST['site_id']."'";
	//$sql1="SELECT * FROM `site_page` WHERE `id`='".$_REQUEST['pid']."' AND site_id='".$_REQUEST['site_id']."'";
	$sql1="SELECT * FROM `site_page` WHERE  `site_id`='".$_REQUEST['site_id']."' ";
//	echo $sql1;
	$result = mysql_query($sql);
	$result1 = mysql_query($sql1);

	$num=1;
	if($data1=mysql_fetch_array($result1))
	{
		$flag=1;
		$pid=$data1['id'];
	}
	
	$pid=$_REQUEST['pid'];
	
	if($data=mysql_fetch_array($result)){
	
	//print_r($data);
?>
<html>
<head>
<title><?php if($flag==1)echo stripslashes($data1["meta_title"]);else echo stripslashes($data["meta_title"]);?></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="keywords" content="<?php if($flag==1)echo stripslashes($data1["meta_keywords"]); else echo $data["meta_keywords"];?>">
<meta name="description" content="<?php if($flag==1)echo stripslashes($data1["meta_description"]); else echo $data["meta_description"];?>">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<style>
.body {
	background-color: #<?php echo $data["page_bg_color"]; ?>;
}
.body,td,th {
	font-size: 14px;
	color: #<?php echo $data["page_tdtext_color"];?>;
	font-weight: bold;
}
a:link {
	color: #<?php echo $data["page_link_text_color"]; ?>;
}
a:visited {
	color: #<?php echo $data["page_link_visited_color"]; ?>;
}
a:hover {
	color: #<?php echo $data["page_link_rollover_color"]; ?>;
}
a:active {
	color: #<?php echo $data["page_link_rollover_color"]; ?>;
}
.h1 {
	font-weight: bold;
	font-size: 24px;
	color: #<?php echo $data["page_text_color"]; ?>;
}
.h2 {
	font-weight: bold;
}
.h3 {
	font-weight: bold;
}
.h4 {
	font-weight: bold;
}
.h5 {
	font-weight: bold;
}
.h6 {
	font-weight: bold;
}
.h2 {
	font-size: 16px;
	color: #<?php echo $data["page_text_color"]; ?>;
}
.style4 {font-size: 14px}
.style7 {
	font-family: Dauphin;
	font-size: 24px;
	color: #<?php echo $data["page_text_color"]; ?>;
}
.style9 {color: #FFFFFF}
.style10 {font-size: 26px}
.style13 {font-size: 36px}
h3 {
	font-size: 16px;
	color: #<?php echo $data["page_text_color"]; ?>;
}
.style8 {font-size: 24px}
.style1 {font-size: 24px;
	font-weight: bold;
	font-style: italic;
	color: #<?php echo $data["page_text_color"]; ?>;
}
</style><body class="body">
<!-- We Offer cd duplication, cd replication, cd rom duplication, cd rom replication, cd duplication services, cheap cd duplication, cd dvd replication, cd business card replication, cd replication services, bulk cd replication Services. Start your own record label. -->
<CENTER><H2><?php if($pid==0){ echo "Under Construction!<BR><BR><a href='#' onclick='javascript:history.back()'>Go Back</a>"; exit; } ?></H2></CENTER>
<table width="100%"  border="0" summary="CD Duplication">
  <tr>
    <th height="698" scope="col"><table width="800" height="696" border="0" align="center" bordercolor="#<?php echo $data["bdr_color1"];?>" summary="cd replication">
      <tr>
        <th height="682" scope="col"><table width="100%"  border="2" align="center" bordercolor="#<?php echo $data["bdr_color2"];?>">
          <tr>
            <th background='photos/header/<?php echo  $_SESSION['SITE_ID'] . "_" . $data["page_bg_image"]; ?>' alt='<?php echo $data["page_bg_image_alt"];?>' scope="col"><table width="100%"  border="0">
                <tr>
                  <th width="21%" height="153" scope="col"><?php
		  if($data["logo"] !=""){ ?>
                  <img src="logos/<?php echo $_SESSION['SITE_ID']."_frontlogo.jpg";//echo $_SESSION['SITE_ID'] . "_" . $data["logo"]; ?>" alt="<?php $log=$data["logo_alt"]; $log=stripslashes($log); $log=str_replace('"','&quot;',$log); echo $log; ?>" width="150" height="149" align="middle"><?php
		  }
		  ?></th>
                  <th width="54%" scope="col">
					  <p align="center"><font face="Arial" size="6"><?php echo nl2br($data["company_name"]); ?></font></p>
					  <p align="center"><font face="Arial" size="2"><?php echo $data["slogan"]; ?></font></td>
				  </th>
                  <th width="25%" scope="col"><?php echo nl2br ($data["contact_info"]); ?></th>
                </tr>
            </table></th>
          </tr>
          <tr>
            <td height="507"><table width="100%"  border="2" bordercolor="<?php echo $data["bdr_color3"];?>">
                <tr>
                  <th width="21%" height="495" align="center" valign="top" background='photos/navbar/<?php echo  $_SESSION['SITE_ID'] . "_" . $data["page_bg_image"]; ?>' scope="col"><table width="100%" height="489"  border="0">
                      <tr>
                        <th valign="top" scope="col" align='left'><table width="100%" border="0" summary="Navbar Table">
					<?php
						$sql="SELECT * FROM `site_navbar` WHERE `site_id`='".$_SESSION['SITE_ID']."' AND `link_active`='Y' AND `link_parent`='0' ORDER BY `link_position`, `link_text`";
						$nav_res = mysql_query($sql);
						//echo $sql;
						while($nav_data=mysql_fetch_array($nav_res)){
							if($nav_data["link_page"] == 10){
								?><tr><td><a target="_self" class="style4" href='shop.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>'><?php
								echo $nav_data["link_text"];
								?></a></td></tr><?php
							}
							else{
								?><tr><td><a target="_self" class="style4" href='page.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>&pid=<?php echo $nav_data["link_page"]; ?>'><?php
								echo $nav_data["link_text"];
								?></a></td></tr><?php

								$sql="SELECT * FROM `site_navbar` WHERE `site_id`='".$_SESSION['SITE_ID']."' AND `link_active`='Y' AND `link_parent`='" . $nav_data['id'] . "' ORDER BY link_position, link_text";
								
							//	echo $sql;

								$nav_res2 = mysql_query($sql);
								while($nav_data2=mysql_fetch_array($nav_res2)){
									?><tr><td style="padding-left:10px"><a target="_self" class="style4" href='page.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>&pid=<?php echo $nav_data2["link_page"]; ?>'><?php
									echo $nav_data2["link_text"];
									?></a></td></tr><?php
								}
							}
						}
					?>                            
                            <tr>
                              <td height="19" align="left"><a href="cart_page.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>&pid=10&cat=none&fst=0&lst=8">Shopping Cart</a></td>
                            </tr>
                        </table></th>
                      </tr>
                  </table></th>
                  <th width="79%" align="center" valign="top" scope="col">
				  
		<table width="100%"  border="0">
				 <?php
				if($Uflag==1)
				{echo"File Uploaded Successfully!!";}
				elseif($Uflag==2)
				{echo"This Reseller is not permitted to upload.";}
				elseif($Uflag==3)
				{echo"This Reseller has no more space to upload.";}
				elseif($Uflag==4)
				{echo"Invalid file Size to upload.";}
				
		$sql="SELECT * FROM `site_page` WHERE id='".$pid."'";

		
		$page_res = mysql_query($sql);
		while($page_data=mysql_fetch_array($page_res)){
			$page_title=$page_data["page_title"];
			$page_content=$page_data["page_content"];
			$page_content_img=$page_data["page_content_img"];
			$page_content_img_alt=$page_data["page_content_img_alt"];
			$page_content_ic=$page_data["page_content_ic"];
			$banner=$page_data["banner"];
			$banner_link=$page_data["banner_link"];
			$page_title=str_replace('&quot;','"',$page_title);
			$page_title=str_replace("''","'",$page_title);
			$page_title=stripslashes($page_title);
			$page_content=str_replace('&quot;','"',$page_content);
			$page_content=str_replace("''","'",$page_content);
			$page_content=stripslashes($page_content);
			$page_content_img_alt=stripslashes($page_content_img_alt);	
			$page_content_img_alt=str_replace('"','&quot;',$page_content_img_alt);					
		
//							&rsquo;&prime;&lsquo;
		}					
		 
				//****************PARSE CODE FOR THE UPLOAD FIELDS****RAO*****
				$uindx=0;				
				do
				{
				if($uindx>strlen($page_content) || $uindx<0)break;
				$upos=strpos($page_content,"****",$uindx);				
				if($upos===false)break;
				$uindx=$upos+4;//index of first label character.<br>* *<br>				
				$uend_pos=strpos($page_content,"*",$uindx);//index of last label character.
				$ulabel=substr($page_content, $uindx, ($uend_pos-$uindx));				
				//echo $ulabel;
				$urepstr='****'.$ulabel.'****';
				$urepwith='<form action="Cfile_upload.php?sid='.$_SESSION['SITE_ID'].'&pid='.$pid.'&lbl='.$ulabel.'" method="post" enctype="multipart/form-data" name="uform"><center>'.$ulabel.' : <input type="file" name="xfile" /><BR><input type="submit" value="Upload File" /></center></form>';
				$page_content=str_replace($urepstr,$urepwith,$page_content);				
				break;
				}while($uindx<strlen($page_content));			
				//****************END PARSING*************************RAO*****			
				
				//*******************************************
				//Myscript to Parse Link in Page Content.
				$indx=1;
				do{
					//echo ":  : ".$indx;
				if($indx>strlen($page_content) || $indx<=0)break;
				$pos=strpos($page_content,"KINGLINKINSERTHERE*",$indx);
				if($pos===false)break;
				$indx=$pos+19;//index of first star character.
				$end_pos=strpos($page_content,"*",$indx);//index of second star character.
				$lnkid=substr($page_content, $indx, ($end_pos-$indx));
				$qq="select * from site_page where id='".$lnkid."'";
				//echo $qq;				
				//exit;
				$rr=mysql_query($qq);
				//echo $rr; //exit;
				$aryy=mysql_fetch_array($rr);
				//echo $aryy["page_title"]; 
				//CHECK IF THE PAGE EXISTS IN PARTICULAR SITE OR NOT.
				if($aryy["page_title"]!="")
				{
						$ltxt=$aryy["page_title"];
						$ltxt=str_replace("'","''",$ltxt);
						$chq="select * from site_page where page_title='".$ltxt."' AND `site_id`=".$_SESSION['SITE_ID'];
						//echo $chq;
						$chr=mysql_query($chq);
						$cary=mysql_fetch_array($chr);
						$chid=$cary["id"];						
				}
				else
				{
					$reptext="<br>KINGLINKINSERTHERE*".$lnkid."*<br>";
					$page_content=str_replace($reptext,"",$page_content);
					$indx=$indx-23;
					continue;
				}
								
				if($chid=="")//IF PAGE DOES'NT EXIST THEN REPLACE THE LINK TAG WITH BLANK.
				{
					$reptext="<br>KINGLINKINSERTHERE*".$lnkid."*<br>";
					$page_content=str_replace($reptext,"",$page_content);
					$indx=$indx-23;
					continue;
				}
				//IF PAGE EXISTS THEN MAKE A LINK TO THE PAGE ID OF THE PAGE OF PARTICULAR RESELLER ID.
				$atext="<a href=\"page.php?site_id=".$_SESSION['SITE_ID']."&pid=".$chid."\">$ltxt</a>";
				$reptext="KINGLINKINSERTHERE*".$lnkid."*";//"<BR>KINGLINKINSERTHERE*".$lnkid."*<BR>";
				$page_content=str_replace($reptext,$atext,$page_content);
				$indx=$end_pos+2;
				}while($indx<strlen($page_content));
				//********** ERROR PRONE *** RAO ****************
				//$page_content=str_replace('"','&quot;',$page_content);
				$page_content=str_replace("''","'",$page_content);
				$page_content=str_replace("<br />","",$page_content);
				//************************************************?>
				
                      <tr>
                       <th width="2%" height="103" scope="col">&nbsp;</th>
                        <th width="96%" align="center" valign="top" scope="col"><table width="100%"  border="0">
                            <tr>
                              <th align="center" valign="top" scope="col"><h1><font color='#<?php echo $data["page_title_color"]; ?>'><?php echo $page_title; ?></font></h1></th>
                            </tr>
                            <tr>
                              <td height="400" valign=top><font color='#<?php echo $data["page_text_color"]; ?>'>
								<?php
								if($banner != ""){ 
								?>
								  <div align=center><a href="<?php echo $banner_link; ?>" target="_n1"><img src="photos/banners/<?php echo $_SESSION['SITE_ID']."_".$banner; ?>" alt='' border=0></a></div><BR>
								<?php
								}
								if("$page_content_img" != ""){ 
									echo "<div align='center'><img src='photos/contents/".$_SESSION['SITE_ID']."_$page_content_img' alt=\"$page_content_img_alt\"></div>";
								}
								$init=0;
								do{$page_content=str_replace("<br />","",$page_content);
								$prod_pos=strpos("$page_content","KINGPRODINSERTHERE",$init);
									//echo "Loop: $page_content<BR>INIT $init $prod_pos<BR>";
								if($prod_pos===false){
									/*echo nl2br(*/echo substr($page_content,$init)/*)*/;
								//echo nl2br($page_content);
								break;
								}
								else{
									echo /*nl2br(*/substr($page_content,$init,$prod_pos-$init)/*)*/;
									$prod_id_pos=strpos($page_content,"<br>", $prod_pos);
									$pro_id=substr($page_content,$prod_pos+18,$prod_id_pos-$prod_pos - 18);
										$sql="SELECT * FROM site_product,product_master WHERE site_product.site_id='".$_SESSION['SITE_ID']."' AND site_product.product_id=product_master.id AND product_master.id='$pro_id'";
										//$sql="SELECT * FROM product_master WHERE id='$pro_id'";

										$result_pro_master = mysql_query($sql);
										if($row_pro_master=mysql_fetch_array($result_pro_master)){
											$product_title=$row_pro_master["product_title"];
											$product_category=$row_pro_master["product_category"];
											$product_desc=$row_pro_master["product_desc"];
											$product_img=$row_pro_master["product_img"];
											$product_img_alt=$row_pro_master["product_img_alt"];
											$price=$row_pro_master["price"];
										}
										else{
											$product_title="";
											$product_desc="";
											$product_img="";
											$product_img_alt="";
											$price="";
										}

										?><TABLE border=1 width="100%" cellpadding=5 cellspacing=0>
										<TR>
											<TH colspan=2><H3><font color='#<?php echo $data["page_title_color"]; ?>'><?php echo $product_title . " (" . $product_category . ")"; ?></font></H3></Th>
										</TR>
										<TR>
											<TD width="150"><img width=100 src="<?php echo "photos/products/${pro_id}_$product_img"; ?>" border=0 alt="<?php echo $product_img_alt; ?>"></TD>

											<TD><font color='#<?php echo $data["page_text_color"]; ?>'><?php echo $product_desc; ?><BR><BR>Price : $<?php echo $price; ?><!-- <BR>Tax : $<?php echo ($price * (100+$tax_pct)/100); ?><BR>Shipping : $<?php echo $shipping_amt; ?> --></font></TD>
										</TR>
										<TR>
											<TH colspan=2><A HREF="basket.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>&pid=<?php echo $pro_id; ?>"><font color='#<?php echo $data["page_text_color"]; ?>'>Buy Now</font></A>&nbsp;<A HREF="cart_details.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>&pid=<?php echo $pro_id; ?>" target="_blank"><font color='#<?php echo $data["page_text_color"]; ?>'>Add To Cart </font></A>&nbsp;<A HREF="cart_view.php?site_id=<?php echo $_SESSION['SITE_ID']; ?>" target="_blank"><font color='#<?php echo $data["page_text_color"]; ?>'>View Cart</font></A></Th>
										</TR>
										</TABLE><BR><?php
									$init=$prod_id_pos+4;
								}
								}
								while(true);

								if($page_content_ic == "C"){ 
									#echo nl2br($page_content);
								}
								else{
									echo "<img src='pages/{$pid}_$page_content_img' alt='$page_content_img'>";
								}
								
								?>
				&nbsp;</font></td>
                            </tr>
                            <tr>
                              <td><h3 align="center"><font color='#<?php echo $data["page_title_color"]; ?>'><?php echo $data["copyright"]; ?></font></h3></td>
                            </tr>
                            <!-- <tr>
                              <td height="21"><h3 align="center">Report any problems with web site to <a href="/Templates/CS@KingOfEnterprise.com">Webmaster@KingOfEnterprise.com</a></h3></td>
                            </tr> -->
                        </table></th>
                        <th width="2%" scope="col">&nbsp;</th>
                      </tr>
                  </table></th>
                </tr>
            </table></td>
          </tr>
        </table></th>
      </tr>
    </table></th>
  </tr>
</table>
</body>
<?php
	}
?>
</html>